# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library", "iree_runtime_cc_test")
load("//build_tools/bazel:cc_binary_benchmark.bzl", "cc_binary_benchmark")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_runtime_cc_library(
    name = "util",
    srcs = ["util.c"],
    hdrs = ["util.h"],
    deps = [
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal",
        "//runtime/src/iree/base/internal:cpu",
        "//runtime/src/iree/base/internal:synchronization",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/schemas:cpu_data",
    ],
)

iree_runtime_cc_library(
    name = "test",
    srcs = ["test.c"],
    hdrs = ["test.h"],
    deps = [
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/schemas:cpu_data",
    ],
)

iree_runtime_cc_test(
    name = "util_test",
    srcs = ["util_test.c"],
    deps = [
        ":test",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:cpu",
        "//runtime/src/iree/schemas:cpu_data",
    ],
)

iree_runtime_cc_library(
    name = "benchmark",
    srcs = ["benchmark.c"],
    hdrs = ["benchmark.h"],
    deps = [
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/schemas:cpu_data",
        "//runtime/src/iree/testing:benchmark",
    ],
)

iree_runtime_cc_library(
    name = "memcpy_benchmark",
    srcs = ["memcpy_benchmark.c"],
    hdrs = ["memcpy_benchmark.h"],
    deps = [
        ":benchmark",
        "//runtime/src/iree/base",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/testing:benchmark",
    ],
)

cc_binary_benchmark(
    name = "mmt4d_benchmark",
    srcs = ["mmt4d_benchmark.c"],
    deps = [
        ":benchmark",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
        "//runtime/src/iree/testing:benchmark",
    ],
)

iree_runtime_cc_test(
    name = "mmt4d_test",
    srcs = ["mmt4d_test.c"],
    deps = [
        ":test",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
    ],
)

cc_binary_benchmark(
    name = "pack_benchmark",
    srcs = ["pack_benchmark.c"],
    deps = [
        ":benchmark",
        ":memcpy_benchmark",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
        "//runtime/src/iree/testing:benchmark",
    ],
)

iree_runtime_cc_test(
    name = "pack_test",
    srcs = ["pack_test.c"],
    deps = [
        ":test",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
    ],
)

cc_binary_benchmark(
    name = "unpack_benchmark",
    srcs = ["unpack_benchmark.c"],
    deps = [
        ":benchmark",
        ":memcpy_benchmark",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
        "//runtime/src/iree/testing:benchmark",
    ],
)

iree_runtime_cc_test(
    name = "unpack_test",
    srcs = ["unpack_test.c"],
    deps = [
        ":test",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:cpu",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
    ],
)

cc_binary_benchmark(
    name = "e2e_matmul_benchmark",
    srcs = ["e2e_matmul_benchmark.c"],
    deps = [
        ":benchmark",
        ":util",
        "//runtime/src/iree/base",
        "//runtime/src/iree/base/internal:flags",
        "//runtime/src/iree/builtins/ukernel",
        "//runtime/src/iree/builtins/ukernel:internal_headers",
        "//runtime/src/iree/testing:benchmark",
    ],
)
